import requestAll from './request' // 此处，引入存放对promise处理的文件
// 画宇测试服务器地址
const apiUrl = 'https://test-wxapp.huayuwujin.cn/hy-apprest/v1_0/'
// const apiUrl = 'http://127.0.0.1:8086/hy_apprest/v1_0/'
// const apiUrl = 'http://localhost:8080/apprest/v1_0/'
// const apiUrl = 'http://127.0.0.1:8086/hy_apprest/v1_0/'

class api {
  // get方法
  getMethod (params, weburl) {
    let data = {
      params
    }
    return requestAll.getRequest(apiUrl + weburl, data)
  }
  postMethod (weburl, params) {
    return requestAll.postRequest(apiUrl + weburl, JSON.stringify(params))
  }
  post (params, weburl) {
    return requestAll.postRequest(apiUrl + weburl, params)
  }
  get (weburl) {
    return requestAll.getRequest(apiUrl + weburl)
  }
  // 获取用户appid
  getUserOpenIdAndSessionKey (weburl, params) {
    return requestAll.postRequest(apiUrl + weburl, JSON.stringify(params))
  }
  toMoney (num) {
    num = num.toFixed(2)
    num = parseFloat(num)
    num = num.toLocaleString()
    return num// 返回的是字符串23,245.12保留2位小数
  }

  toMoney2 (val) {
    var str = (val / 100 * 100).toFixed(2) + ''
    var intSum = str.substring(0, str.indexOf('.')).replace(/\B(?=(?:\d{3})+$)/g, ',')
    var dot = str.substring(str.length, str.indexOf('.'))
    var ret = intSum + dot
    return ret
  }
}

// 暴露接口
export default {
  api: api
}
